{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer\n",
    "import json\n",
    "from tqdm import tqdm\n",
    "import sys\n",
    "sys.path.append('../src')\n",
    "import torch\n",
    "\n",
    "from utils.callbacks import Iteratorize, Stream\n",
    "from utils.prompter import Prompter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Adjust batch size based on model and machine capabilities\n",
    "batch_size = 8\n",
    "max_seq_len = 1024\n",
    "max_samples = 20\n",
    "\n",
    "# Specify the path to your local model\n",
    "model_path = \"/mnt/metaMathFineTuning/meta-math/MetaMath-Mistral-7B/\"\n",
    "tokenizer_path = \"/mnt/metaMathFineTuning/meta-math/MetaMath-Mistral-7B/\"\n",
    "\n",
    "# Specify the path to your dataset and where to save the answers\n",
    "val_dataset_path = \"../datasets/TAL-SAQ6K/TAL-SAQ6K-EN.jsonl\"\n",
    "answers_path = \"../data/answers.json\"\n",
    "\n",
    "# Define the instruction template\n",
    "instruction_template = (\n",
    "    \"Below is an instruction that describes a task. \"\n",
    "    \"Write a response that appropriately completes the request.\\n\\n\"\n",
    "    \"### Instruction:\\n{problem}\\n\\n\"\n",
    "    \"### Response: Let's think step by step.\"\n",
    ")\n",
    "\n",
    "prompt_template = \"../templates/metamath.json\"\n",
    "\n",
    "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "698e0cf087f0407e868e09172618433b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Loading checkpoint shards:   0%|          | 0/2 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Load the tokenizer and model\n",
    "tokenizer = AutoTokenizer.from_pretrained(tokenizer_path,padding=True,truncation=True)\n",
    "model = AutoModelForCausalLM.from_pretrained(\n",
    "        model_path,\n",
    "        load_in_8bit=True,\n",
    "        # torch_dtype=torch.float16,\n",
    "        # device_map=\"auto\",\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "prompter = Prompter(prompt_template)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['{\"dataset_version\": \"2023-07-07\", \"queId\": \"559135fce0cc43d09bcdb784b6b68b16\", \"difficulty\": \"1\", \"qtype\": \"short_answer\", \"problem\": \"$$5^{2}+6^{2}+7^{2}+\\\\\\\\cdots +15^{2}$$. \", \"knowledge_point_routes\": [\"Overseas Competition->Knowledge Point->Calculation Modules->Operations through Formulas->1²+2²+3²+......+n²=1/6n(n+1)(n+2)\"]}\\n',\n",
       " '{\"dataset_version\": \"2023-07-07\", \"queId\": \"3ae45bd14e7f417c9f717caaa1c8e5f6\", \"difficulty\": \"1\", \"qtype\": \"short_answer\", \"problem\": \"There are $206$ bones in the human body. The bones in the hands account for $\\\\\\\\dfrac{27}{103}$~of the total. If the finger bones account for $\\\\\\\\dfrac{14}{27}$~of the total hand bones, how many finger bones are there in the human body? \", \"knowledge_point_routes\": [\"Overseas Competition->Knowledge Point->Word Problem Modules->Solving Problems Involving Fractions and Percentages->Knowing the Base\"]}\\n',\n",
       " '{\"dataset_version\": \"2023-07-07\", \"queId\": \"b59c5c8afae1475392bc408efcd4db9b\", \"difficulty\": \"0\", \"qtype\": \"short_answer\", \"problem\": \"The math class in Think Academy starts at $9:00$ and ends at $10:00$. How long does the whole class last? \", \"knowledge_point_routes\": [\"Overseas Competition->Knowledge Point->Combinatorics->Time Problem\"]}\\n',\n",
       " '{\"dataset_version\": \"2023-07-07\", \"queId\": \"5c4e76cbed394941b52264c055387694\", \"difficulty\": \"1\", \"qtype\": \"short_answer\", \"problem\": \"Jia Jia spent $20 \\\\\\\\%$ of her money on a bag and $40 \\\\\\\\%$ of the remainder on a skirt. If she had $ $90$ left, how much did she have at first? $ $$~\\\\\\\\uline{~~~~~~~~~~}~ \", \"knowledge_point_routes\": [\"Overseas Competition->Knowledge Point->Calculation Modules\"]}\\n',\n",
       " '{\"dataset_version\": \"2023-07-07\", \"queId\": \"04ba6a8bbd934c9fb2c34951b1c5e1b9\", \"difficulty\": \"2\", \"qtype\": \"short_answer\", \"problem\": \"Students from Year 4 line up and form a square array, and there is a surplus of $5$ students. If one row and one column are added to form a larger square array, $26$ more students are needed. Find the number of students in Year 4. \", \"knowledge_point_routes\": [\"Overseas Competition->Knowledge Point->Word Problem Modules->Questions Involving Squares->Solid Squares\"]}\\n',\n",
       " '{\"dataset_version\": \"2023-07-07\", \"queId\": \"7598dc1e2b3942f987670ac551b91e44\", \"difficulty\": \"1\", \"qtype\": \"short_answer\", \"problem\": \"$36$ students each went to one revision class.  $\\\\\\\\dfrac{1}{6}$~of the students went to the physics revision class.  $\\\\\\\\dfrac{2}{9}$~of the students went to the biology revision class.  All of the other students went to the chemistry revision class.  How many students went to the chemistry revision class? \", \"knowledge_point_routes\": [\"Overseas Competition->Knowledge Point->Word Problem Modules->Solving Problems Involving Fractions and Percentages->Knowing the Base\"]}\\n',\n",
       " '{\"dataset_version\": \"2023-07-07\", \"queId\": \"55d37813feb54cc0939c8d521cc804ed\", \"difficulty\": \"1\", \"qtype\": \"short_answer\", \"problem\": \"Amy has $$37$$ apples and John has $$15$$ apples. How many apples does Amy have to give John so that she has exactly $$4$$ more apples than John? \", \"knowledge_point_routes\": [\"Overseas Competition->Knowledge Point->Word Problem Modules->Questions Involving Sum, Difference and Multiples->Problems Involving Sum and Difference\"]}\\n',\n",
       " '{\"dataset_version\": \"2023-07-07\", \"queId\": \"f0976cf87d42410886ef671aee576759\", \"difficulty\": \"1\", \"qtype\": \"short_answer\", \"problem\": \"$$167-43=$$~\\\\\\\\uline{~~~~~~~~~~}~ \", \"knowledge_point_routes\": [\"Overseas Competition->Knowledge Point->Calculation Modules->Whole Numbers->Whole Numbers Addition and Subtraction \"]}\\n']"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "with open(val_dataset_path, 'r', encoding='utf-8') as file:\n",
    "    lines = file.readlines()\n",
    "lines = lines[:batch_size]\n",
    "lines"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[\"Below is an instruction that describes a task. Write a response that appropriately completes the request.\\n\\n### Instruction:\\n$$5^{2}+6^{2}+7^{2}+\\\\cdots +15^{2}$$. \\n\\n### Response: Let's think step by step.\"]\n"
     ]
    }
   ],
   "source": [
    "problem = \"$$5^{2}+6^{2}+7^{2}+\\\\cdots +15^{2}$$. \"\n",
    "# prompt = prompter.generate_prompt(problem)\n",
    "prompt = [instruction_template.format(problem=problem)]\n",
    "print(prompt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[\"Below is an instruction that describes a task. Write a response that appropriately completes the request.\\n\\n### Instruction:\\n$$5^{2}+6^{2}+7^{2}+\\\\cdots +15^{2}$$. \\n\\n### Response: Let's think step by step.\",\n",
       " \"Below is an instruction that describes a task. Write a response that appropriately completes the request.\\n\\n### Instruction:\\nThere are $206$ bones in the human body. The bones in the hands account for $\\\\dfrac{27}{103}$~of the total. If the finger bones account for $\\\\dfrac{14}{27}$~of the total hand bones, how many finger bones are there in the human body? \\n\\n### Response: Let's think step by step.\",\n",
       " \"Below is an instruction that describes a task. Write a response that appropriately completes the request.\\n\\n### Instruction:\\nThe math class in Think Academy starts at $9:00$ and ends at $10:00$. How long does the whole class last? \\n\\n### Response: Let's think step by step.\",\n",
       " \"Below is an instruction that describes a task. Write a response that appropriately completes the request.\\n\\n### Instruction:\\nJia Jia spent $20 \\\\%$ of her money on a bag and $40 \\\\%$ of the remainder on a skirt. If she had $ $90$ left, how much did she have at first? $ $$~\\\\uline{~~~~~~~~~~}~ \\n\\n### Response: Let's think step by step.\",\n",
       " \"Below is an instruction that describes a task. Write a response that appropriately completes the request.\\n\\n### Instruction:\\nStudents from Year 4 line up and form a square array, and there is a surplus of $5$ students. If one row and one column are added to form a larger square array, $26$ more students are needed. Find the number of students in Year 4. \\n\\n### Response: Let's think step by step.\",\n",
       " \"Below is an instruction that describes a task. Write a response that appropriately completes the request.\\n\\n### Instruction:\\n$36$ students each went to one revision class.  $\\\\dfrac{1}{6}$~of the students went to the physics revision class.  $\\\\dfrac{2}{9}$~of the students went to the biology revision class.  All of the other students went to the chemistry revision class.  How many students went to the chemistry revision class? \\n\\n### Response: Let's think step by step.\",\n",
       " \"Below is an instruction that describes a task. Write a response that appropriately completes the request.\\n\\n### Instruction:\\nAmy has $$37$$ apples and John has $$15$$ apples. How many apples does Amy have to give John so that she has exactly $$4$$ more apples than John? \\n\\n### Response: Let's think step by step.\",\n",
       " \"Below is an instruction that describes a task. Write a response that appropriately completes the request.\\n\\n### Instruction:\\n$$167-43=$$~\\\\uline{~~~~~~~~~~}~ \\n\\n### Response: Let's think step by step.\"]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "formatted_problems = [\n",
    "                instruction_template.format(\n",
    "                    problem=json.loads(line)['problem'])\n",
    "                for line in lines\n",
    "            ]\n",
    "formatted_problems"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'input_ids': tensor([[    1, 20811,   349,   396, 13126,   369, 13966,   264,  3638, 28723,\n",
       "          12018,   264,  2899,   369,  6582,  1999,  2691,   274,   272,  2159,\n",
       "          28723,    13,    13, 27332,  3133,  3112, 28747,    13, 10811, 28782,\n",
       "            984, 28750,  9969, 28784,   984, 28750,  9969, 28787,   984, 28750,\n",
       "          13582, 11797,   648, 28740, 28782,   984, 28750,  1211,  1715, 28705,\n",
       "             13,    13, 27332, 12107, 28747,  3169, 28742, 28713,  1073,  3707,\n",
       "            486,  3707, 28723, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000],\n",
       "         [    1, 20811,   349,   396, 13126,   369, 13966,   264,  3638, 28723,\n",
       "          12018,   264,  2899,   369,  6582,  1999,  2691,   274,   272,  2159,\n",
       "          28723,    13,    13, 27332,  3133,  3112, 28747,    13,  5816,   460,\n",
       "            429, 28750, 28734, 28784, 28776, 15262,   297,   272,  2930,  2187,\n",
       "          28723,   415, 15262,   297,   272,  3038,  2708,   354,   878, 28715,\n",
       "           1655, 28751, 28750, 28787,  1400, 28740, 28734, 28770,  1211, 28845,\n",
       "           1009,   272,  3102, 28723,  1047,   272,  9728, 15262,  2708,   354,\n",
       "            878, 28715,  1655, 28751, 28740, 28781,  1400, 28750, 28787,  1211,\n",
       "          28845,  1009,   272,  3102,  1021, 15262, 28725,   910,  1287,  9728,\n",
       "          15262,   460,   736,   297,   272,  2930,  2187, 28804, 28705,    13,\n",
       "             13, 27332, 12107, 28747,  3169, 28742, 28713,  1073,  3707,   486,\n",
       "           3707, 28723, 32000, 32000, 32000, 32000, 32000, 32000, 32000],\n",
       "         [    1, 20811,   349,   396, 13126,   369, 13966,   264,  3638, 28723,\n",
       "          12018,   264,  2899,   369,  6582,  1999,  2691,   274,   272,  2159,\n",
       "          28723,    13,    13, 27332,  3133,  3112, 28747,    13,  1014, 11049,\n",
       "            875,   297, 15403, 10819,  8383,   438,   429, 28774, 28747, 28734,\n",
       "          28734, 28776,   304,  9675,   438,   429, 28740, 28734, 28747, 28734,\n",
       "          28734,  1715,  1602,  1043,  1235,   272,  2894,   875,  1432, 28804,\n",
       "          28705,    13,    13, 27332, 12107, 28747,  3169, 28742, 28713,  1073,\n",
       "           3707,   486,  3707, 28723, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000],\n",
       "         [    1, 20811,   349,   396, 13126,   369, 13966,   264,  3638, 28723,\n",
       "          12018,   264,  2899,   369,  6582,  1999,  2691,   274,   272,  2159,\n",
       "          28723,    13,    13, 27332,  3133,  3112, 28747,    13, 28798,   515,\n",
       "            475,   515,  5223,   429, 28750, 28734,   414, 28823, 28776,   302,\n",
       "            559,  2445,   356,   264,  6635,   304,   429, 28781, 28734,   414,\n",
       "          28823, 28776,   302,   272, 23317,   356,   264, 24784, 28723,  1047,\n",
       "            630,   553,   429,   429, 28774, 28734, 28776,  1749, 28725,   910,\n",
       "           1188,   863,   630,   506,   438,   907, 28804,   429,  5623,  2658,\n",
       "            353,   473, 28751, 22770,  4836, 28752, 28845, 28705,    13,    13,\n",
       "          27332, 12107, 28747,  3169, 28742, 28713,  1073,  3707,   486,  3707,\n",
       "          28723, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000],\n",
       "         [    1, 20811,   349,   396, 13126,   369, 13966,   264,  3638, 28723,\n",
       "          12018,   264,  2899,   369,  6582,  1999,  2691,   274,   272,  2159,\n",
       "          28723,    13,    13, 27332,  3133,  3112, 28747,    13, 18262,   788,\n",
       "            477,  7601, 28705, 28781,  1407,   582,   304,  1221,   264,  7930,\n",
       "           2293, 28725,   304,   736,   349,   264,  1147, 11269,   302,   429,\n",
       "          28782, 28776,  3567, 28723,  1047,   624,  5150,   304,   624,  4419,\n",
       "            460,  3886,   298,  1221,   264,  6084,  7930,  2293, 28725,   429,\n",
       "          28750, 28784, 28776,   680,  3567,   460,  3236, 28723,  8769,   272,\n",
       "           1474,   302,  3567,   297,  7601, 28705, 28781, 28723, 28705,    13,\n",
       "             13, 27332, 12107, 28747,  3169, 28742, 28713,  1073,  3707,   486,\n",
       "           3707, 28723, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000],\n",
       "         [    1, 20811,   349,   396, 13126,   369, 13966,   264,  3638, 28723,\n",
       "          12018,   264,  2899,   369,  6582,  1999,  2691,   274,   272,  2159,\n",
       "          28723,    13,    13, 27332,  3133,  3112, 28747,    13, 28776, 28770,\n",
       "          28784, 28776,  3567,  1430,  2068,   298,   624, 24935,   875, 28723,\n",
       "          28705,   878, 28715,  1655, 28751, 28740,  1400, 28784,  1211, 28845,\n",
       "           1009,   272,  3567,  2068,   298,   272, 16173, 24935,   875, 28723,\n",
       "          28705,   878, 28715,  1655, 28751, 28750,  1400, 28774,  1211, 28845,\n",
       "           1009,   272,  3567,  2068,   298,   272,  4240,  2161, 24935,   875,\n",
       "          28723, 28705,  1682,   302,   272,   799,  3567,  2068,   298,   272,\n",
       "          25691, 24935,   875, 28723, 28705,  1602,  1287,  3567,  2068,   298,\n",
       "            272, 25691, 24935,   875, 28804, 28705,    13,    13, 27332, 12107,\n",
       "          28747,  3169, 28742, 28713,  1073,  3707,   486,  3707, 28723],\n",
       "         [    1, 20811,   349,   396, 13126,   369, 13966,   264,  3638, 28723,\n",
       "          12018,   264,  2899,   369,  6582,  1999,  2691,   274,   272,  2159,\n",
       "          28723,    13,    13, 27332,  3133,  3112, 28747,    13, 28741,  1916,\n",
       "            659,  5623, 28770, 28787, 10811,   979,  2815,   304,  2215,   659,\n",
       "           5623, 28740, 28782, 10811,   979,  2815, 28723,  1602,  1287,   979,\n",
       "           2815,  1235, 17723,   506,   298,  2111,  2215,   579,   369,   630,\n",
       "            659,  4668,  5623, 28781, 10811,   680,   979,  2815,   821,  2215,\n",
       "          28804, 28705,    13,    13, 27332, 12107, 28747,  3169, 28742, 28713,\n",
       "           1073,  3707,   486,  3707, 28723, 32000, 32000, 32000, 32000, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000],\n",
       "         [    1, 20811,   349,   396, 13126,   369, 13966,   264,  3638, 28723,\n",
       "          12018,   264,  2899,   369,  6582,  1999,  2691,   274,   272,  2159,\n",
       "          28723,    13,    13, 27332,  3133,  3112, 28747,    13, 10811, 28740,\n",
       "          28784, 28787, 28733, 28781, 28770,  8991, 28776,  2658,   353,   473,\n",
       "          28751, 22770,  4836, 28752, 28845, 28705,    13,    13, 27332, 12107,\n",
       "          28747,  3169, 28742, 28713,  1073,  3707,   486,  3707, 28723, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "          32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000]],\n",
       "        device='cuda:0'),\n",
       " 'attention_mask': tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
       "          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
       "          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n",
       "         [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0],\n",
       "         [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
       "          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n",
       "         [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n",
       "         [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n",
       "         [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],\n",
       "         [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
       "          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n",
       "         [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "          1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
       "          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
       "          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],\n",
       "        device='cuda:0')}"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inputs = tokenizer(formatted_problems, return_tensors='pt', padding=True, truncation=True, max_length=512)\n",
    "inputs = {key: tensor.to(device) for key, tensor in inputs.items()}\n",
    "inputs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Setting `pad_token_id` to `eos_token_id`:2 for open-end generation.\n"
     ]
    }
   ],
   "source": [
    "# Generate answers using the model\n",
    "with torch.no_grad():\n",
    "    outputs = model.generate(\n",
    "        **inputs, max_length=512, num_beams=2, temperature=1.0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([    1, 20811,   349,   396, 13126,   369, 13966,   264,  3638, 28723,\n",
       "        12018,   264,  2899,   369,  6582,  1999,  2691,   274,   272,  2159,\n",
       "        28723,    13,    13, 27332,  3133,  3112, 28747,    13,  1014, 11049,\n",
       "          875,   297, 15403, 10819,  8383,   438,   429, 28774, 28747, 28734,\n",
       "        28734, 28776,   304,  9675,   438,   429, 28740, 28734, 28747, 28734,\n",
       "        28734,  1715,  1602,  1043,  1235,   272,  2894,   875,  1432, 28804,\n",
       "        28705,    13,    13, 27332, 12107, 28747,  3169, 28742, 28713,  1073,\n",
       "         3707,   486,  3707, 28723, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "        32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "        32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "        32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,\n",
       "        32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000, 32000,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     1,     1,     1,     1,     1,     1,     1,     1,     1,\n",
       "            1,     0], device='cuda:0')"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "outputs[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[\"<s> Below is an instruction that describes a task. Write a response that appropriately completes the request.\\n\\n### Instruction:\\n$$5^{2}+6^{2}+7^{2}+\\\\cdots +15^{2}$$. \\n\\n### Response: Let's think step by step.[PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD]<s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><unk>\",\n",
       " \"<s> Below is an instruction that describes a task. Write a response that appropriately completes the request.\\n\\n### Instruction:\\nThere are $206$ bones in the human body. The bones in the hands account for $\\\\dfrac{27}{103}$~of the total. If the finger bones account for $\\\\dfrac{14}{27}$~of the total hand bones, how many finger bones are there in the human body? \\n\\n### Response: Let's think step by step.[PAD][PAD][PAD][PAD][PAD][PAD][PAD]<s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><unk>\",\n",
       " \"<s> Below is an instruction that describes a task. Write a response that appropriately completes the request.\\n\\n### Instruction:\\nThe math class in Think Academy starts at $9:00$ and ends at $10:00$. How long does the whole class last? \\n\\n### Response: Let's think step by step.[PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD]<s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><unk>\",\n",
       " \"<s> Below is an instruction that describes a task. Write a response that appropriately completes the request.\\n\\n### Instruction:\\nJia Jia spent $20 \\\\%$ of her money on a bag and $40 \\\\%$ of the remainder on a skirt. If she had $ $90$ left, how much did she have at first? $ $$~\\\\uline{~~~~~~~~~~}~ \\n\\n### Response: Let's think step by step.[PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD]<s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><unk>\",\n",
       " \"<s> Below is an instruction that describes a task. Write a response that appropriately completes the request.\\n\\n### Instruction:\\nStudents from Year 4 line up and form a square array, and there is a surplus of $5$ students. If one row and one column are added to form a larger square array, $26$ more students are needed. Find the number of students in Year 4. \\n\\n### Response: Let's think step by step.[PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD]<s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><unk>\",\n",
       " \"<s> Below is an instruction that describes a task. Write a response that appropriately completes the request.\\n\\n### Instruction:\\n$36$ students each went to one revision class.  $\\\\dfrac{1}{6}$~of the students went to the physics revision class.  $\\\\dfrac{2}{9}$~of the students went to the biology revision class.  All of the other students went to the chemistry revision class.  How many students went to the chemistry revision class? \\n\\n### Response: Let's think step by step.<s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><unk>\",\n",
       " \"<s> Below is an instruction that describes a task. Write a response that appropriately completes the request.\\n\\n### Instruction:\\nAmy has $$37$$ apples and John has $$15$$ apples. How many apples does Amy have to give John so that she has exactly $$4$$ more apples than John? \\n\\n### Response: Let's think step by step.[PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD]<s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><unk>\",\n",
       " \"<s> Below is an instruction that describes a task. Write a response that appropriately completes the request.\\n\\n### Instruction:\\n$$167-43=$$~\\\\uline{~~~~~~~~~~}~ \\n\\n### Response: Let's think step by step.[PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD][PAD]<s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><s><unk>\"]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# decode the generated answer\n",
    "# answer = tokenizer.decode(outputs[0], skip_special_tokens=True)\n",
    "# answer\n",
    "\n",
    "# # Decode the generated answers\n",
    "batch_answers = tokenizer.batch_decode(outputs, skip_special_tokens=False)\n",
    "batch_answers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "torch.cuda.empty_cache()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "myconda",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
